/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * GUI.java
 *
 * Created on Apr 8, 2011, 2:51:52 PM
 */

package IpChat_For_Testing;

//import GUI.*;
import javax.swing.text.*;
import java.awt.Color;

/**
 *
 * @author Wei Liang
 */


public class GUI extends javax.swing.JFrame {


    /** Creates new form GUI */
    public GUI() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        chatPanel = new javax.swing.JPanel();
        sendT = new javax.swing.JButton();
        sendA = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        chatM = new javax.swing.JTextArea();
        jScrollPane1 = new javax.swing.JScrollPane();
        chatH = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        sendT.setText("Send to Team");
        sendT.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sendTMouseClicked(evt);
            }
        });

        sendA.setText("Send to All");
        sendA.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                sendAMouseClicked(evt);
            }
        });

        chatM.setColumns(20);
        chatM.setRows(5);
        jScrollPane2.setViewportView(chatM);

        jScrollPane1.setAutoscrolls(true);

        chatH.setEditable(false);
        jScrollPane1.setViewportView(chatH);

        javax.swing.GroupLayout chatPanelLayout = new javax.swing.GroupLayout(chatPanel);
        chatPanel.setLayout(chatPanelLayout);
        chatPanelLayout.setHorizontalGroup(
            chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chatPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 569, Short.MAX_VALUE)
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 329, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(sendT, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                            .addComponent(sendA, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE))))
                .addContainerGap())
        );
        chatPanelLayout.setVerticalGroup(
            chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chatPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(sendT, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(sendA, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(chatPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(163, 163, 163)
                .addComponent(chatPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void sendTMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sendTMouseClicked
        // TODO add your handling code here:
        IpChat_Main.sendT(chatM.getText());
        chatM.setText(null);
       // System.out.flush();
    }//GEN-LAST:event_sendTMouseClicked

    private void sendAMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_sendAMouseClicked
        // TODO add your handling code here:
        IpChat_Main.sendA(chatM.getText());
        chatM.setText(null);
       // System.out.flush();
    }//GEN-LAST:event_sendAMouseClicked

    /**
    * @param args the command line arguments
    */
    /*
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new GUI().setVisible(true);
            }
        });
    }
     *
     */

    //<editor-fold desc="Methods(own)">


    public void setchatM(String test){
        chatM.setText(test);
    }

    public String getchatM(){
        String msg = chatM.getText();
        return msg;
    }


    public void setchatH(){
        StyledDocument doc = chatH.getStyledDocument();

        Style Red = doc.addStyle("Red", null);
        StyleConstants.setForeground(Red, Color.red);

        Style Blue = doc.addStyle("Blue", null);
        StyleConstants.setForeground(Blue, Color.blue);
    }



    
    public void addchatH(String msgH, String color){
        StyledDocument doc = chatH.getStyledDocument();
        try {
            if(color == null ? "Blue" == null : color.equals("Blue"))
                doc.insertString(doc.getLength(),"\n" + msgH, doc.getStyle("Blue"));
           
            else
                doc.insertString(doc.getLength(),"\n" + msgH, doc.getStyle("Red"));
            
        } catch (BadLocationException e) {
         e.printStackTrace(); 
         }
       
    }





    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextPane chatH;
    private javax.swing.JTextArea chatM;
    private javax.swing.JPanel chatPanel;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton sendA;
    private javax.swing.JButton sendT;
    // End of variables declaration//GEN-END:variables

}
